﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.EquipmentManagement.EquipmentSpotTemplateVMs
{
    public partial class EquipmentSpotTemplateListVM : BasePagedListVM<EquipmentSpotTemplate_View, EquipmentSpotTemplateSearcher>
    {
        
        protected override IEnumerable<IGridColumn<EquipmentSpotTemplate_View>> InitGridHeader()
        {
            return new List<GridColumn<EquipmentSpotTemplate_View>>{
                
                this.MakeGridHeader(x => x.EquipmentSpotTemplate_Name).SetTitle(@Localizer["Page.模板名称"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTemplate_Description).SetTitle(@Localizer["Page.模板说明"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTemplate_SpotCycle).SetTitle(@Localizer["Page.点检周期"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTemplate_SysAuto).SetTitle(@Localizer["Page.系统自动"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTemplate_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTemplate_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTemplate_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotTemplate_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<EquipmentSpotTemplate_View> GetSearchQuery()
        {
            var query = DC.Set<EquipmentSpotTemplate>()
                
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.Description, x=>x.Description)
                .CheckEqual(Searcher.SpotCycle, x=>x.SpotCycle)
                .CheckEqual(Searcher.SysAuto, x=>x.SysAuto)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new EquipmentSpotTemplate_View
                {
				    ID = x.ID,
                    
                    EquipmentSpotTemplate_Name = x.Name,
                    EquipmentSpotTemplate_Description = x.Description,
                    EquipmentSpotTemplate_SpotCycle = x.SpotCycle,
                    EquipmentSpotTemplate_SysAuto = x.SysAuto,
                    EquipmentSpotTemplate_CreateTime = x.CreateTime,
                    EquipmentSpotTemplate_UpdateTime = x.UpdateTime,
                    EquipmentSpotTemplate_CreateBy = x.CreateBy,
                    EquipmentSpotTemplate_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class EquipmentSpotTemplate_View: EquipmentSpotTemplate
    {
        
        public string EquipmentSpotTemplate_Name { get; set; }
        public string EquipmentSpotTemplate_Description { get; set; }
        public decimal? EquipmentSpotTemplate_SpotCycle { get; set; }
        public bool? EquipmentSpotTemplate_SysAuto { get; set; }
        public DateTime? EquipmentSpotTemplate_CreateTime { get; set; }
        public DateTime? EquipmentSpotTemplate_UpdateTime { get; set; }
        public string EquipmentSpotTemplate_CreateBy { get; set; }
        public string EquipmentSpotTemplate_UpdateBy { get; set; }

    }

}